//
//  JZBWebViewController.m
//  JZB
//
//  Created by liujianlong on 2022/9/5.
//

#import "JZBWebViewController.h"
#import <WebKit/WebKit.h>

@interface JZBWebViewController ()<WKNavigationDelegate>
@property (strong, nonatomic) IBOutlet WKWebView *webview;
@end

@implementation JZBWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.webview.navigationDelegate = self;
    self.title = LS(@"隐私协议");
    NSString *url  = [@"https://baike.baidu.com" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:url]];
    request.HTTPMethod = @"GET";
    [self.webview loadRequest:request];
    self.webview.scrollView.bouncesZoom = NO;
    if (@available(iOS 11.0, *)) {
        self.webview.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [RLHud startHud];
}
- (void)backBtnAction
{
    if (self.navigationController.viewControllers.count >= 2) {
        [super backBtnAction];
    }else{
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
- (IBAction)actionforbtn:(UIButton *)sender {
    [self backBtnAction];
}

#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
{
    [RLHud startHud];
}
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation
{
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
    [RLHud stopHud];
}
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation
{
    [RLHud startHud:LS(@"加载失败") stopTime:1 handle:nil];
    
}
- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation
{
    [RLHud  startHud];
}

// 跳转失败时调用
- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error
{
}
@end
